<template>
	<view class="content">
		<swiper class="uswiepr" previous-margin="20rpx" next-margin="20rpx" circular :autoplay="true" :interval="3000"
			:duration="1000">
			<swiper-item class="uswiper-item" v-for="(item,index) in swiperList" :key="index">
				<image class="uimage" :src="item.image" mode="scaleToFill">
				</image>
			</swiper-item>
			<swiper-item class="uswiper-item" v-for="(item,index) in swiperList" :key="index">
				<image class="uimage" :src="item.image" mode="scaleToFill">
				</image>
			</swiper-item>
			<swiper-item class="uswiper-item" v-for="(item,index) in swiperList" :key="index">
				<image class="uimage" :src="item.image" mode="scaleToFill">
				</image>
			</swiper-item>

		</swiper>

		<view class="Nav">
			<view class="nav_item" v-if="index<=9" v-for="(item,index) in navbar" :key="index"
				@click="goDivide(item.id,item.name)">
				<image class="nav_img" :src="item.pic_image" mode="aspectFit"></image>
				<view class="">
					{{item.name}}
				</view>
			</view>
		</view>
		</image>
		<swiper class="uswiepr1" :autoplay="true" :interval="3000" :duration="1000">
			<swiper-item v-for="(item,index) in AdList" :key="index">
				<image class="adimage" :src="item.image" mode="">
				</image>
			</swiper-item>

		</swiper>
		<view class="Shop">
			<view class="Shop_item" v-for="item in ShopList" :key="item.id" @click="navto(item)">
				<image class="Shop_img" :src="item.pic_image" mode=""></image>
				<view class="Shop_text">
					<view class="Shop_text_title">{{item.name}}</view>
					<view class="Shop_money">
						<view class="Shop_content">{{item.shop_content}}</view>
						<view class="Shop_address">{{item.address}}</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getShopBy,
		getShopType,
		getAd,
	} from '../../utls/api.js'

	export default {
		data() {
			return {
				navbar: [],
				ShopList: [],
				code: '',
				page: 1,
				page_num: 10,
				total: null,
				swiperList: [],
				AdList: [],
				share_id: uni.getStorageSync('info').share_id, //分享者id
			}
		},
		onLoad(e) {
			if (e.share_id) {
				uni.setStorageSync('share_id', e.share_id);
				console.log(e.share_id)
			}
		},
		onShow() {
			if (uni.getStorageSync('info').is_vip == 1) {
				uni.showShareMenu({
					withShareTicket: true,
					menus: ['shareAppMessage', 'shareTimeline'] //开启转发好友和转发朋友圈按钮
				});
			} else {
				uni.hideShareMenu({
					hideShareItems: ['shareTimeline', 'shareMenu']
				})
			}
		},
		onShareAppMessage: function(e) { // 分享到微信
			// 更多参数配置，参考文档
			let path = getCurrentPages();
			let route = path[path.length - 1].route;
			console.log(route, uni.getStorageSync('info').share_id)
			return {
				title: '同城泉友',
				path: `/${route}?share_id=${uni.getStorageSync('info').share_id}`,
			}
		},

		onShareTimeline() { // 分享到朋友圈
			let path = getCurrentPages();
			let route = path[path.length - 1].route;
			return {
				title: '同城泉友',
				path: `/${route}?share_id=${uni.getStorageSync('info').share_id}`,
			}
		},

		mounted() {

			this.ShopBy();
			getShopType().then(res => {
				// console.log(res)
				this.navbar = res.data.data;
			})
			// 广告
			getAd({
				ad_position_id: 1
			}).then(res => {
				console.log("广告", res)
				if (res.data.code == 1) {
					this.AdList = res.data.data.data;
				}
			})
			// banner图
			getAd({
				ad_position_id: 9
			}).then(res => {
				if (res.data.code == 1) {
					this.swiperList = res.data.data.data;
				}
				console.log("banner", res)
			})

		},
		onReachBottom() {
			console.log("到底了")
			this.page++;
			this.ShopBy()
		},
		methods: {
			ShopBy() {
				getShopBy({
					page: this.page,
					page_num: this.page_num,
				}).then(res => {
					console.log(res)
					if (res.data.code == 1) {
						this.ShopList = [...this.ShopList, ...res.data.data.data];
						this.total = res.data.data.total;
					}
				});
			},
			navto(item) {
				uni.setStorageSync('ShopDetail', item);
				uni.navigateTo({
					url: `./Shopdetail`,
					success: res => {},
					fail: () => {},
					complete: () => {}
				});
			},
			goDivide(id, title) {
				uni.setStorageSync('Divide_id', id)
				uni.setStorageSync('Divide_title', title)
				uni.switchTab({
					url: '/pages/Divide/Divide',
					success: (res) => {
						console.log(res)
					}
				});
			}
		}
	}
</script>

<style scoped lang="scss">
	.content {
		padding: 20rpx;
		background-color: white;
	}

	.Nav {
		display: flex;
		flex-wrap: wrap;
		margin: 20rpx 0;

		.nav_item {
			width: 20%;
			display: flex;
			align-items: center;
			justify-content: center;
			flex-direction: column;
			margin: 10rpx 0rpx;
			font-size: 20rpx;

			.nav_img {
				width: 70rpx;
				height: 70rpx;
				margin-bottom: 10rpx;
			}
		}
	}

	.uswiepr {
		border-radius: 10rpx;
		overflow: hidden;
		height: 300rpx;

		.uswiper-item {
			text-align: center;
		}

		.uimage {
			width: 98%;
			height: 300rpx;
			border-radius: 10rpx;
		}

		.adimage {
			width: 100%;
			height: 200rpx;
			border-radius: 10rpx;
		}
	}

	.uswiepr1 {
		border-radius: 10rpx;
		overflow: hidden;

		.uimage {
			width: 100%;
			height: 300rpx;
		}

		.adimage {
			width: 100%;
			height: 200rpx;
			border-radius: 10rpx;
		}
	}

	.Shop {
		display: flex;
		flex-wrap: wrap;
		justify-content: space-between;

		.Shop_item {
			width: 48%;
			margin: 20rpx 0;
			background-color: white;
			border-radius: 10rpx 10rpx 10rpx 10rpx;
			overflow: hidden;
			box-shadow: 0 0 10rpx 10rpx #f9f9f9;

			.Shop_img {
				width: 100%;
				height: 300rpx;
			}

			.Shop_text {
				padding: 10rpx 20rpx;

				.Shop_text_title {
					font-size: 26rpx;
					color: #111;
					font-weight: 600;
					margin-bottom: 10rpx;
					white-space: nowrap;
					overflow: hidden;
					text-overflow: ellipsis;
				}

				.Shop_money {
					font-size: 22rpx;
					white-space: nowrap;

					.Shop_content {
						text-overflow: ellipsis;
						overflow: hidden;
						color: #999;
					}

					.Shop_address {
						color: #444444;
						font-size: 22rpx;
						text-overflow: ellipsis;
						overflow: hidden;
						color: #999;
					}
				}
			}
		}
	}
</style>